<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:rich="http://richfaces.org/rich"
	xmlns:s="http://jboss.com/products/seam/taglib"
	xmlns:m="http://www.ol4jsf.org"
	xmlns:a4j="http://richfaces.org/a4j"
	xmlns:o="http://openfaces.org/">

	<h:form rendered="#{not dataEntryHelper.rrrHelper.editingRights and not dataEntryHelper.rrrHelper.editingRestrictions}">
		<a4j:jsFunction name="editingResponsibilitiesFun"
		rendered="#{not dataEntryHelper.rrrHelper.editingResponsibilities}"
		reRender="panelResponsibilities">
			<f:setPropertyActionListener value="#{true}" target="#{dataEntryHelper.rrrHelper.editingResponsibilities}" />
		</a4j:jsFunction>
		
		<a4j:jsFunction name="cancelResponsibilityChangesFun"
		action="#{dataEntryHelper.rrrHelper.cancelResponsibilityChanges}"
		rendered="#{dataEntryHelper.rrrHelper.editingResponsibilities}"
		reRender="panelResponsibilities">
		</a4j:jsFunction>
		
		<a4j:jsFunction name="applyResponsibilityChangesFun"
		action="#{dataEntryHelper.rrrHelper.applyResponsibilityChanges}"
		rendered="#{dataEntryHelper.rrrHelper.editingResponsibilities}"
		reRender="panelResponsibilities">
		</a4j:jsFunction>
		
		<a4j:jsFunction name="addNewResponsibilityFun"
		rendered="#{dataEntryHelper.rrrHelper.editingResponsibilities}"
		oncomplete="#{rich:component('panelModiResponsibilities')}.show(); #{rich:component('selectPartyPanel')}.show()">
			<f:setPropertyActionListener target="#{selectNaturalPersonExtPartyHelper.addToList}" value="#{true}" />
			<f:setPropertyActionListener target="#{selectNaturalPersonExtPartyHelper.selectedPartyField}" value="dataEntryHelper.rrrHelper.selectedNaturalPerson" />
			<f:setPropertyActionListener target="#{selectNaturalPersonExtPartyHelper.addToListMethod}" value="dataEntryHelper.rrrHelper.addNewResponsibility" />
			<f:setPropertyActionListener target="#{selectNaturalPersonExtPartyHelper.reRenderComponents}" value="#{rich:clientId('newResponsibilitiesTable')}" />
		</a4j:jsFunction>
		
		<a4j:jsFunction name="modifySelectedResponsibilitiesFun"
		action="#{dataEntryHelper.rrrHelper.modifySelectedResponsibilities}"
		rendered="#{not empty dataEntryHelper.rrrHelper.parcelResponsibilitiesList and dataEntryHelper.rrrHelper.editingResponsibilities}"
		reRender="responsibilitiesTable,newResponsibilitiesTable"
		oncomplete="#{rich:component('panelModiResponsibilities')}.show();">
		</a4j:jsFunction>
		
		<a4j:jsFunction name="deleteSelectedResponsibilitiesFun"
		rendered="#{not empty dataEntryHelper.rrrHelper.parcelResponsibilitiesList and dataEntryHelper.rrrHelper.editingResponsibilities}"
		action="#{dataEntryHelper.rrrHelper.deleteSelectedResponsibilities}"
		reRender="responsibilitiesTable,newResponsibilitiesTable">
		</a4j:jsFunction>
		
		
		<rich:toolBar height="20" itemSeparator="grid">
			<rich:toolBarGroup>
				<h:panelGroup>
					<o:commandButton type="button" onclick="editingResponsibilitiesFun();"
					disabled="#{dataEntryHelper.rrrHelper.editingResponsibilities}">
						<rich:toolTip followMouse="true" direction="bottom-right" showDelay="500" styleClass="tooltip">
							<span style="white-space:nowrap">
								#{messages['dataentry.mutate_responsibilities.btn_edit']}
							</span>
						</rich:toolTip>
						<h:graphicImage value="/img/edit.gif" />
					</o:commandButton>
	
					<o:commandButton type="button" onclick="cancelResponsibilityChangesFun();"
					disabled="#{not dataEntryHelper.rrrHelper.editingResponsibilities}">
						<rich:toolTip followMouse="true" direction="bottom-right" showDelay="500" styleClass="tooltip">
							<span style="white-space:nowrap">
								#{messages['dataentry.mutate_responsibilities.btn_cancel']}
							</span>
						</rich:toolTip>
						<h:graphicImage value="/img/cancel-icon.png" width="16px" height="16px" />
					</o:commandButton>
	
					<o:commandButton type="button" onclick="applyResponsibilityChangesFun();"
					disabled="#{not dataEntryHelper.rrrHelper.editingResponsibilities}">
						<rich:toolTip followMouse="true" direction="bottom-right" showDelay="500" styleClass="tooltip">
							<span style="white-space:nowrap">
								#{messages['dataentry.mutate_responsibilities.btn_save']}
							</span>
						</rich:toolTip>
						<h:graphicImage value="/img/save-icon.png" width="16px" height="16px" />
					</o:commandButton>
				</h:panelGroup>
			</rich:toolBarGroup>
			
			<rich:toolBarGroup>
				<h:panelGroup>
					<o:commandButton type="button" onclick="addNewResponsibilityFun();"
					disabled="#{not dataEntryHelper.rrrHelper.editingResponsibilities}">
						<rich:toolTip followMouse="true" direction="bottom-right" showDelay="500" styleClass="tooltip">
							<span style="white-space:nowrap">
								#{messages['dataentry.mutate_responsibilities.btn_add_new_one']}
							</span>
						</rich:toolTip>
						<h:graphicImage value="/img/add-icon.png" />
					</o:commandButton>
					
					<o:commandButton type="button" onclick="modifySelectedResponsibilitiesFun();"
					disabled="#{empty dataEntryHelper.rrrHelper.parcelResponsibilitiesList or not dataEntryHelper.rrrHelper.editingResponsibilities}">
						<rich:toolTip followMouse="true" direction="bottom-right" showDelay="500" styleClass="tooltip">
							<span style="white-space:nowrap">
								#{messages['dataentry.mutate_responsibilities.btn_modify_selected']}
							</span>
						</rich:toolTip>
						<h:graphicImage value="/img/edit.gif" />
					</o:commandButton>
					
					<o:commandButton type="button" onclick="deleteSelectedResponsibilitiesFun();"
					disabled="#{empty dataEntryHelper.rrrHelper.parcelResponsibilitiesList or not dataEntryHelper.rrrHelper.editingResponsibilities}">
						<rich:toolTip followMouse="true" direction="bottom-right" showDelay="500" styleClass="tooltip">
							<span style="white-space:nowrap">
								#{messages['dataentry.mutate_responsibilities.btn_delete_selected']}
							</span>
						</rich:toolTip>
						<h:graphicImage value="/img/delete-icon.png" />
					</o:commandButton>
				</h:panelGroup>
			</rich:toolBarGroup>
		</rich:toolBar>
		
		<div align="center" style="height:450px;" class="contentResponsibilities">
			<br />
			<strong>#{messages['dataentry.mutate_responsibilities.current']}</strong>
			<rich:separator lineType="solid"/>
			<br />
			<h:panelGroup id="responsibilitiesTable">
				<h:panelGroup rendered="#{not empty dataEntryHelper.rrrHelper.parcelResponsibilitiesList}">
					<rich:dataTable style="vertical-align:baseline;" value="#{dataEntryHelper.rrrHelper.parcelResponsibilitiesList}" var="responsibility" rowKeyVar="row" cellspacing="1" rows="13">
						<rich:column rendered="#{dataEntryHelper.rrrHelper.editingResponsibilities}">
							<f:facet name="header">
								<h:outputText value="#{messages['dataentry.mutate_rrr.edit']}"/>
							</f:facet>
							<h:selectBooleanCheckbox value="#{responsibility.selected}"/>
						</rich:column>
						<rich:column>
							<f:facet name="header">
								<h:outputText value="#{messages['dataentry.mutate_rrr.party']}"/>
							</f:facet>
							<h:outputText value="#{responsibility.owner}"/>
						</rich:column>
						<rich:column>
							<f:facet name="header">
								<h:outputText value="#{messages['dataentry.mutate_responsibilities.type']}"/>
							</f:facet>
							<h:outputText value="#{messages[responsibility.typeString]}" />
						</rich:column>
						<rich:column style="text-align:right;">
							<f:facet name="header">
								<h:outputText value="#{messages['dataentry.mutate_rrr.share']}"/>
							</f:facet>
							<h:outputText value="#{responsibility.shareString}"/>
						</rich:column>
	
						<f:facet name="footer">
							<rich:columnGroup>
								<rich:column>#{messages['dataentry.mutate_rrr.total']}</rich:column>
								<rich:column colspan="3" style="text-align:right;">
									<h:outputText value="#{dataEntryHelper.rrrHelper.responsibilitiesSumShares}"/>
								</rich:column>
							</rich:columnGroup>
						</f:facet>
					</rich:dataTable>
					<br />
					<br />
				</h:panelGroup>
				
				<h:panelGroup rendered="#{empty dataEntryHelper.rrrHelper.parcelResponsibilitiesList}">
					<h:outputText value="#{messages['dataentry.mutate_responsibilities.no']}" />
					<br />
				</h:panelGroup>
			</h:panelGroup>
		
			<br/>
			<br/>
		
		</div>
	</h:form>
	
	<rich:modalPanel id="panelModiResponsibilities" width="550" height="530" zindex="10500">
		<f:facet name="header">
			<h:panelGroup>
				<h:outputText value="#{messages['dataentry.mutate_responsibilities.new']}"></h:outputText>
			</h:panelGroup>
		</f:facet>
		<f:facet name="controls">
			<h:panelGroup>
				<h:graphicImage value="/img/close.png" styleClass="hidelink"
				onclick="modiResponsibilitiesCancel()" />
			</h:panelGroup>
		</f:facet>
		
		<h:form>
			<a4j:jsFunction name="addNewFun" oncomplete="#{rich:component('selectPartyPanel')}.show()">
				<f:setPropertyActionListener target="#{selectNaturalPersonExtPartyHelper.addToList}" value="#{true}" />
				<f:setPropertyActionListener target="#{selectNaturalPersonExtPartyHelper.selectedPartyField}" value="dataEntryHelper.rrrHelper.selectedNaturalPerson" />
				<f:setPropertyActionListener target="#{selectNaturalPersonExtPartyHelper.addToListMethod}" value="dataEntryHelper.rrrHelper.addNewResponsibility" />
				<f:setPropertyActionListener target="#{selectNaturalPersonExtPartyHelper.reRenderComponents}" value="#{rich:clientId('newResponsibilitiesTable')}" />
			</a4j:jsFunction>
			
			<a4j:jsFunction name="acceptResponsibilitiesModificationFun"
			action="#{dataEntryHelper.rrrHelper.acceptResponsibilitiesModification}"
			reRender="responsibilitiesTable, newResponsibilitiesTable"
			oncomplete="if (#{facesContext.maximumSeverity == null}) #{rich:component('panelModiResponsibilities')}.hide();">
			</a4j:jsFunction>
			
			<a4j:jsFunction name="modiResponsibilitiesCancelFun" immediate="true" ajaxSingle="true"
			action="#{dataEntryHelper.rrrHelper.cancelResponsibilitiesModification}"
			reRender="responsibilitiesTable, newResponsibilitiesTable"
			oncomplete="#{rich:component('panelModiResponsibilities')}.hide();">
			</a4j:jsFunction>

			<rich:toolBar itemSeparator="grid">
				<rich:toolBarGroup>
					<o:commandButton type="button" onclick="addNewFun();">
						<rich:toolTip followMouse="true" direction="bottom-right" showDelay="500" styleClass="tooltip">
							<span style="white-space:nowrap">
								#{messages['dataentry.mutate_rrr.btn_add_new']}
							</span>
						</rich:toolTip>
						<h:graphicImage value="/img/add-icon.png" />
					</o:commandButton>
				</rich:toolBarGroup>
				
				<rich:toolBarGroup location="right">
					<h:panelGroup>
						<o:commandButton type="button" onclick="acceptResponsibilitiesModificationFun();">
							<rich:toolTip followMouse="true" direction="bottom-left" showDelay="500" styleClass="tooltip">
								<span style="white-space:nowrap">
									#{messages['dataentry.mutate_rrr.btn_accept_changes']}
								</span>
							</rich:toolTip>
							<h:graphicImage value="/img/accept-icon.png" width="16px" height="16px" />
						</o:commandButton>
		
						<o:commandButton type="button" onclick="modiResponsibilitiesCancelFun()">
							<rich:toolTip followMouse="true" direction="bottom-left" showDelay="500" styleClass="tooltip">
								<span style="white-space:nowrap">
									#{messages['dataentry.mutate_rrr.btn_cancel_changes']}
								</span>
							</rich:toolTip>
							<h:graphicImage value="/img/cancel-icon.png" width="16px" height="16px" />
						</o:commandButton>
					</h:panelGroup>
				</rich:toolBarGroup>
			</rich:toolBar>
			
			<br/>
			
			<div align="center">
				<h:panelGroup id="newResponsibilitiesTable">
					<h:panelGroup rendered="#{not empty dataEntryHelper.rrrHelper.newParcelResponsibilitiesList}">
						<div style="height:400px;" class="contentResponsibilities">
						<rich:dataTable value="#{dataEntryHelper.rrrHelper.newParcelResponsibilitiesList}" var="newResponsibility" rowKeyVar="row">
							<f:facet name="header">
								<rich:columnGroup>
									<rich:column breakBefore="true" rowspan="2">
										<h:outputText value="#{messages['dataentry.mutate_rrr.party']}"/>
									</rich:column>
									<rich:column rowspan="2">
										<h:outputText value="#{messages['dataentry.mutate_responsibilities.type']}"/>
									</rich:column>
									<rich:column colspan="2">
										<h:outputText value="#{messages['dataentry.mutate_rrr.share']}"/>
									</rich:column>
									<rich:column breakBefore="true">
										<h:outputText value="#{messages['dataentry.mutate_rrr.numerator']}"/>
									</rich:column>
									<rich:column>
										<h:outputText value="#{messages['dataentry.mutate_rrr.denominator']}"/>
									</rich:column>
								</rich:columnGroup>
							</f:facet>
							
							<rich:column>
								<a4j:commandLink id="editNameLink" oncomplete="#{rich:component('selectPartyPanel')}.show()">
									<f:setPropertyActionListener target="#{dataEntryHelper.rrrHelper.selectedResponsibility}" value="#{newResponsibility}"/>
									
									<f:setPropertyActionListener target="#{selectNaturalPersonExtPartyHelper.addToList}" value="#{false}" />
									<f:setPropertyActionListener target="#{selectNaturalPersonExtPartyHelper.selectedPartyField}" value="dataEntryHelper.rrrHelper.selectedResponsibility.extParty" />
									<f:setPropertyActionListener target="#{selectNaturalPersonExtPartyHelper.reRenderComponents}" value="#{rich:clientId('newResponsibilitiesTable')}" />
									
									<h:outputText value="#{newResponsibility.owner}"/>
								</a4j:commandLink>
							</rich:column>
							<rich:column>
								<h:selectOneMenu value="#{newResponsibility.rrrType}">
									<f:selectItems value="#{dataEntryHelper.rrrHelper.responsibilityTypes}"/>
								</h:selectOneMenu>
							</rich:column>
							<rich:column style="text-align:right;">
								<rich:inputNumberSpinner value="#{newResponsibility.share.numerator}" minValue="0" maxValue="100" step="1" style=" width : 39px;"/>
							</rich:column>
							<rich:column style="text-align:right;">
								<rich:inputNumberSpinner value="#{newResponsibility.share.denominator}" minValue="0" maxValue="100" step="1" style=" width : 39px;"/>
							</rich:column>
							
							<f:facet name="footer">
								<rich:columnGroup>
									<rich:column>#{messages['dataentry.mutate_rrr.total']}</rich:column>
									<rich:column colspan="3" style="text-align:right;">
										<h:outputText value="#{dataEntryHelper.rrrHelper.responsibilitiesSumNewShares}"/>
									</rich:column>
								</rich:columnGroup>
							</f:facet>
						</rich:dataTable>
						</div>
						<br />
						<br />
					</h:panelGroup>
					<h:panelGroup rendered="#{empty dataEntryHelper.rrrHelper.newParcelResponsibilitiesList}">
						<div align="center">
							<h:outputText value="#{messages['dataentry.mutate_responsibilities.no_new']}" />
						</div>
					</h:panelGroup>
				</h:panelGroup>
			</div>
		</h:form>
	</rich:modalPanel>
</ui:composition>
